//
//  StockConfidenceRemainJa.m
//  MarketDataColloctor
//
//  Created by jiro on 10/02/28.
//  Copyright 2010 jiro music. All rights reserved.
//

#import "StockConfidenceRemainJa.h"
#import "DbUtility.h"

@implementation StockConfidenceRemainJa

@synthesize sellRemain;
@synthesize buyRemain;
@synthesize sellVariation;
@synthesize buyVariation;
@synthesize confidenceRate;

+ (id) stockConfidenceRemainJaWithDbRespose: (NSArray*) values
{
	StockConfidenceRemainJa* ret	= [ [ StockConfidenceRemainJa alloc ] init ];
	ret.code				= [ values objectAtIndex: 0 ];
	ret.exchangeDate		= [ NSDate dateWithString: [ DbUtility convertIsoStdDateStringToCocoaDateString: [ values objectAtIndex: 1 ] ] ];
	ret.sellRemain			= [ [ values objectAtIndex: 2 ] floatValue ];
	ret.buyRemain			= [ [ values objectAtIndex: 3 ] floatValue ];
	ret.sellVariation		= [ [ values objectAtIndex: 2 ] floatValue ];
	ret.buyVariation		= [ [ values objectAtIndex: 3 ] floatValue ];
	ret.confidenceRate		= [ [ values objectAtIndex: 4 ] floatValue ];
	return ret;
}

+(NSString*) tableName
{
	return kText_StockConfidenceRemainJaTable;
}

+ (NSString*) queryCreateTable
{ 
	NSString* s = [ NSString stringWithFormat: @"create table %@ ( %@ %@, %@ %@( %d ), %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@ %@, %@( %@, %@, %@ ) );",
		[ StockConfidenceRemainJa tableName ],
		kText_Code, kText_Text,
		kText_MarketInitial, kText_VarChar, 4,
		kText_ExchangeDate, kText_TimestampWithTimeZone, 
		kText_SellRemain, kText_Real,
		kText_BuyRemain, kText_Real,
		kText_SellVariation, kText_Real,
		kText_BuyVariation, kText_Real,
		kText_ConfidenceRate, kText_Real,
		kText_PrimaryKey, kText_Code, kText_MarketInitial, kText_ExchangeDate
	];
	return s;
}

- (NSString*) tableName
{
	return [ StockConfidenceRemainJa tableName ];
}

- (NSString*) sqlInsertStatement
{
	return [ NSString stringWithFormat: @"insert into %@ values %@",
		kText_StockConfidenceRemainJaTable, [ self queryInsertValue ] ];
}

+ (NSString*) querySelectAll
{
	NSString* s = [ NSString stringWithFormat: @"select * from %@;", [ StockConfidenceRemainJa tableName ] ];
	return s;
}

- (NSString*) queryInsert
{
	NSString* s = [ NSString stringWithFormat: @"insert into * values %@;", 
		[ StockConfidenceRemainJa tableName ], [ self queryInsertValue ] ];
	return s;
}

- (NSString*) queryInsertValue
{
	return [ NSString stringWithFormat: @"( '%@', '%@', %f, %f, %f, %f, %f )",
		code, [ exchangeDate description ], sellRemain, buyRemain, sellVariation, buyVariation, confidenceRate ];
}

@end
